﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsAE2.ascx.cs" Inherits="Admin_Module_News_Controls_NewsAE2" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<div id="tabs">
    <ul>
        <li><a href="#tabs-1"><b>Thêm sửa tin tức</b></a></li>
    </ul>
    <div id="tabs-1">
        <a href='/Admin/Module/News/NewsList.aspx'>
            <div style="text-align: right">
                <input type="button" class="ui-widget-content ui-corner-all textfield cursor" value="Danh sách loại tin" /></div>
        </a>
    </div>
    <table class="gridadd">
        <tr>
            <td>
                Tiêu đề
            </td>
            <td>
                <asp:TextBox ID="txtName" runat="server" CssClass="ui-widget-content ui-corner-all textfield"
                    Width="570px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                    ControlToValidate="txtName"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                Tóm tắc
            </td>
            <td>
                <asp:TextBox ID="txtSummary" runat="server" CssClass="ui-widget-content ui-corner-all textfield"
                    Width="570px" Height="100px" TextMode="MultiLine"></asp:TextBox>
                <%-- <FCKeditorV2:FCKeditor ID="txtSummary" runat="server" ToolbarSet="MyBasic" Width="570px"
                    Height="200px" EditorAreaCSS="ui-widget-content ui-corner-all textfield">
                </FCKeditorV2:FCKeditor>--%>
            </td>
        </tr>
        <tr>
            <td>
                Nội dụng
            </td>
            <td>
                <asp:ScriptManager ID="ScriptManager1" runat="server" />
                <%--  <FCKeditorV2:FCKeditor ID="txtDescription" runat="server" ToolbarSet="MyBasic" Width="570px"
                    Height="400px" EditorAreaCSS="ui-widget-content ui-corner-all textfield">
                </FCKeditorV2:FCKeditor>--%>
                <telerik:RadEditor Width="783" Height="500" ID="radEditorContent" ToolsFile="~/App_Data/Xml/DefaultToolbar.xml"
                    runat="server" Skin="Default" EditModes="All" NewLineBr="True" EnableEmbeddedScripts="true"
                    StripFormattingOptions="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll" StripFormattingOnPaste="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll"
                    ToolbarMode="Default" SpellCheckSettings-AllowAddCustom="false" EnableResize="false"
                    OnClientCommandExecuted="OnClientCommandExecuted" OnClientPasteHtml="OnClientPasteHtml1"
                    ContentFilters="DefaultFilters">
                    <CssFiles>
                        <telerik:EditorCssFile Value="/css/Editor.css" />
                    </CssFiles>
                    <ContextMenus>
                        <telerik:EditorContextMenu TagName="P">
                            <telerik:EditorTool Name="CustomApplyCSS_Title" ShowIcon="false" Text="pTitle" />
                            <telerik:EditorTool Name="CustomApplyCSS_Head" ShowIcon="false" Text="pHead" />
                            <telerik:EditorTool Name="CustomApplyCSS_Body" ShowIcon="false" Text="pBody" />
                            <telerik:EditorTool Name="CustomApplyCSS_InterTitle" ShowIcon="false" Text="pInterTitle" />
                            <telerik:EditorTool Name="CustomApplyCSS_SubTitle" ShowIcon="false" Text="pSubTitle" />
                            <telerik:EditorTool Name="CustomApplyCSS_Caption" ShowIcon="false" Text="pCaption" />
                            <telerik:EditorTool Name="CustomApplyCSS_Question" ShowIcon="false" Text="pQuestion" />
                            <telerik:EditorTool Name="CustomApplyCSS_Author" ShowIcon="false" Text="pAuthor" />
                            <telerik:EditorTool Name="CustomApplyCSS_Source" ShowIcon="false" Text="pSource" />
                        </telerik:EditorContextMenu>
                    </ContextMenus>
                </telerik:RadEditor>
                <script language="javascript" type="text/javascript">
                    var regexWhiteSpace = new RegExp("<(p[^>]*)>(((\&nbsp;)*\s*)*)?</p>|<(p[^>]*)><(span[^>]*)>(((\&nbsp;)*\s*)*)?</span></p>|<(font[^>]*)>|<(/font[^>]*)>|<o:p>|</o:p>|<(st1[^>]*)>|<(/st1[^>]*)>|&nbsp;", "gi");
                    var regexP = new RegExp("(<p|<P)[^>]*>(.*?)(<\/P>|<\/p>)", "gi");
                    var regexOpenDIV = new RegExp("(<div|<DIV)[^>]*>", "gi");
                    var regexCloseDIV = new RegExp("(<\/DIV>|<\/div>)", "gi");
                    /*var regexSpan = new RegExp("(<span[^*>]*>)|(<\/span>)|(<SPAN[^*>]*>)|(<\/SPAN>)", "gi");*/
                    var regexSpan = new RegExp("(<span|<SPAN)[^>]*>(.*?)(<\/SPAN>|<\/span>)", "gi");
                    /*var regexFont = new RegExp("(<font[^*>]*>)|(<\/font>)|(<FONT[^*>]*>)|(<\/FONT>)", "gi");*/
                    var regexFont = new RegExp("(<font|<FONT)[^>]*>(.*?)(<\/FONT>|<\/font>)", "gi");
                    var regexStrong = new RegExp("(<strong[^*>]*>)|(<\/strong>)|(<STRONG[^*>]*>)|(<\/STRONG>)", "gi");
                    var regexB = new RegExp("(<b|<B)[^>]*>(.*?)(<\/B>|<\/b>)", "gi");
                    var regexU = new RegExp("(<u|<U)[^>]*>(.*?)(<\/U>|<\/u>)", "gi");
                    var regexI = new RegExp("(<i|<I)[^>]*>(.*?)(<\/I>|<\/i>)", "gi");
                    var regexTABLE = new RegExp("(<table|<TABLE)[^>]*>(.*?)(<\/TABLE>|<\/table>)", "gi");
                    var regexH1 = new RegExp("(<h1|<H1)[^>]*>(.*?)(<\/H1>|<\/h1>)", "gi");
                    var regexH2 = new RegExp("(<h2|<H2)[^>]*>(.*?)(<\/H2>|<\/h2>)", "gi");
                    var regexEM = new RegExp("(<em|<EM)[^>]*>(.*?)(<\/EM>|<\/em>)", "gi");
                    var regexA = new RegExp("(<a|<A)[^>]*>(.*?)(<\/A>|<\/a>)", "gi");
                    var regexUL = new RegExp("(<ul|<UL)[^>]*>(.*?)(<\/UL>|<\/ul>)", "gi");
                    var regexBlockquote = new RegExp("(<blockquote|<BLOCKQUOTE)[^>]*>(.*?)(<\/BLOCKQUOTE>|<\/blockquote>)", "gi");

                    function OnClientPasteHtml1(editor, args) {
                        var commandName = args.get_commandName();
                        var value = args.get_value();

                        if (commandName == "Paste") {
                            var pasteContent = value;
                            pasteContent = pasteContent.replace(regexOpenDIV, "<P class=pBody>");
                            pasteContent = pasteContent.replace(regexCloseDIV, "</P>");
                            pasteContent = pasteContent.replace(regexP, "<P class=pBody>$2</P>").replace(regexWhiteSpace, " ");
                            pasteContent = pasteContent.replace(regexSpan, "<P class=pBody>$2</P>");
                            /*pasteContent = pasteContent.replace(regexFont, "");*/
                            pasteContent = pasteContent.replace(regexFont, "$2");
                            pasteContent = pasteContent.replace(regexStrong, "");
                            pasteContent = pasteContent.replace(regexB, "$2");
                            pasteContent = pasteContent.replace(regexU, "$2");
                            pasteContent = pasteContent.replace(regexI, "$2");
                            pasteContent = pasteContent.replace(regexTABLE, "");
                            pasteContent = pasteContent.replace(regexH1, "<P class=pBody>$2</P>");
                            pasteContent = pasteContent.replace(regexH2, "<P class=pBody>$2</P>");
                            pasteContent = pasteContent.replace(regexEM, "$2");
                            pasteContent = pasteContent.replace(regexA, "$2");
                            pasteContent = pasteContent.replace(regexUL, "<P class=\'pBody\'>$2</P>").replace(regexWhiteSpace, " ");
                            pasteContent = pasteContent.replace(regexBlockquote, "<P class=\'pBody\'>$2</P>").replace(regexWhiteSpace, " ");
                            pasteContent = pasteContent.replace(/size|SIZE = ([\d]{1})/g, '');

                            //set the modified pasted content in the editor
                            args.set_value(pasteContent);
                        }
                    }


                    function OnClientCommandExecuted(editor, args) {
                        if ("ApplyClass" == args.get_commandName()) {
                            var content = editor.get_html(true);
                            content = content.replace(/span/gi, "p");
                            editor.set_html(content);
                        }
                    }


                    // Insert Image From List Into Editor Content
                    Telerik.Web.UI.Editor.CommandList["CustomImageManager"] = function (commandName, radEditorContent, args) {
                        var insertImageCallbackFunction = function (sender, args) {
                            if (!args.IsCancel) {
                                var html = GetImageAttribute(args);
                                radEditorContent.pasteHtml(html);
                            }
                        };
                        // Indent
                        Telerik.Web.UI.Editor.CommandList["CustomerIndent"] = function (commandName, editor, args) {
                            editor.pasteHtml('<span style="width:200px;border: 1px dashed #bb0000;background-color: #fafafa;color: blue;"> ' + args.get_value() + ' </span>');
                        };

                        radEditorContent.showExternalDialog(
                                    '' + '/Admin/Module/FileManager/InsertFTPImage.aspx', {},
                                    800, 620, insertImageCallbackFunction, null, null, true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                    };

                    // Insert Document From List Into Editor Content
                    Telerik.Web.UI.Editor.CommandList["CustomDocumentManager"] = function (commandName, radEditorContent, args) {

                        var argument = radEditorContent.getSelectionHtml();
                        var insertDocumentCallbackFunction = function (sender, args) {
                            if (!args.IsCancel) {
                                var html = GetDocumentAttribute(args);
                                radEditorContent.pasteHtml(html);
                            }
                        };

                        radEditorContent.showExternalDialog(
                                '' + '/Admin/Module/FileManager/InsertFTPDocument.aspx', argument,
                                780, 550, insertDocumentCallbackFunction, null, null, true,
                                Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                    };

                    // Flash Video
                    Telerik.Web.UI.Editor.CommandList["CustomVideoManager"] = function (commandName, radEditorContent, args) {
                        var insertVideoCallbackFunction = function (sender, args) {
                            if (!args.IsCancel) {
                                var html = GetVideoAttribute(args);
                                radEditorContent.pasteHtml(html);
                            }
                        }

                        radEditorContent.showExternalDialog(
                                    '' + '/Admin/Module/FileManager/InsertVideo.aspx', {},
                                    800, 620, insertVideoCallbackFunction, null, null, true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                    };

                    // Insert Custom Audio
                    Telerik.Web.UI.Editor.CommandList["CustomAudioManager"] = function (commandName, radEditorContent, args) {
                        var insertAudioCallbackFunction = function (sender, args) {
                            if (!args.IsCancel) {
                                var html = GetAudioAttribute(args);
                                radEditorContent.pasteHtml(html);
                            }
                        }

                        radEditorContent.showExternalDialog(
                                    '' + '/Admin/Module/FileManager/InsertAudio.aspx',
                                    {},
                                    800,
                                    620,
                                    insertAudioCallbackFunction,
                                    null,
                                    null,
                                    true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                                    false,
                                    true);

                    };



                    function selectThumb() {
                        var radEditorContent = $find("<%= DialogOpener1.ClientID %>");
                        radEditorContent.openUrl("/Admin/Module/FileManager/InsertFTPImage.aspx", {}, 800, 600, selectThumbComplete, null, "custom link manager", true);
                    }

                    function clearThumb() {
                        $('#<%= imgThumb.ClientID %>').attr("scr", "");
                        $('#<%= hdfimg.ClientID %>').val("");
                    }
                    var selectThumbComplete = function (sender, args) {
                        if (!args.IsCancel) {
                            if (args.Url.length > 0) {
                                var img = document.getElementById("<%= imgThumb.ClientID %>");
                                img.src = args.Url;
                                $('#<%= hdfimg.ClientID %>').val(args.Url);
                                // alert($('#<%= hdfimg.ClientID %>').val());

                            }
                        }
                    }
                </script>
                <script language="javascript" type="text/javascript">
                    // App Style for Paragraph
                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Title"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pTitle';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Head"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pHead';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Body"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pBody';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_InterTitle"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pInterTitle';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_SubTitle"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pSubTitle';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Caption"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pCaption';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Question"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pQuestion';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Author"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pAuthor';
                    };

                    Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Source"] = function (commandName, radEditorContent, args) {
                        var objPara = radEditorContent.getSelectedElement();
                        objPara.className = 'pSource';
                    };
                </script>
            </td>
        </tr>
        <tr>
            <td>
                Loại tin
            </td>
            <td>
                <asp:DropDownList ID="ddlCategory" runat="server" CssClass="ui-widget-content ui-corner-all textfield"
                    AppendDataBoundItems="true">
                    <asp:ListItem Text="***** Loại tin *****" Value="" Selected="True"></asp:ListItem>
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
                    ControlToValidate="ddlCategory"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                Trạng thái
            </td>
            <td>
                <asp:CheckBox ID="cbIsVisible" runat="server" Checked="true" />
            </td>
        </tr>
        <tr>
            <td>
                Tin nổi bật
            </td>
            <td>
                <asp:CheckBox ID="cbHot" runat="server" Checked="true" />
            </td>
        </tr>
        <tr>
            <td>
                Hình ảnh:
            </td>
            <td valign="top">
                <%-- <asp:FileUpload ID="FileUpload1" runat="server" CssClass="ui-widget-content ui-corner-all textfield" />&nbsp;&nbsp;&nbsp;<asp:Image
                    ID="Image1" runat="server" Width="50px" Height="50px" CssClass="ui-widget-content ui-corner-all textfield" />--%>
                <div class="inside">
                    <div style="width: 80px; height: 80px; border: solid thin orange;">
                        <asp:Image ID="imgThumb" runat="server" EnableViewState="true" AlternateText="Ảnh đại diện"
                            ToolTip="Ảnh đại diện tour" Width="80px" Height="80px" />
                        <asp:HiddenField ID="hdfimg" runat="server" />
                    </div>
                    <div>
                        <telerik:DialogOpener runat="server" ID="DialogOpener1"></telerik:DialogOpener>
                        <input type="button" id="btnSelectThumb" value="Chọn" style="width: 40px;" onclick="selectThumb()" />
                        <input type="button" id="btnClearThumb" value="Xóa" style="width: 40px;" onclick="clearThumb()" />
                    </div>
                </div>
            </td>
        </tr>
        <%if (!NewsId.Equals(Guid.Empty))
          { %>
        <tr>
            <td>
                Người tạo
            </td>
            <td>
                <asp:Label ID="lblCreatedBy" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Ngày tạo
            </td>
            <td>
                <asp:Label ID="lblCreatedDate" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Người sửa
            </td>
            <td>
                <asp:Label ID="lblUpdatedBy" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Người sửa
            </td>
            <td>
                <asp:Label ID="lblUpdatedDate" runat="server"></asp:Label>
            </td>
        </tr>
        <%} %>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <asp:Button ID="btnUpdate" runat="server" Width="100px" Text="Thêm" CssClass="ui-widget-content ui-corner-all textfield"
                    OnClick="btnUpdate_Click" />
            </td>
        </tr>
    </table>
</div>
</div> 